package adv7.bank2;

//账号
public class Account {
	private String no;
	private int money;

	private String kaihuriqi;

	public Account(String n) {
		this.no = n;
	}

	public Account(int n) {
		this.money = n;
	}

	public Account(String n, int m) {
		this.no = n;
		this.money = m;
	}

	public String getNo() {
		return no;
	}

	public int getMoney() {
		return money;
	}

	public void deposit(int m) {
		money += m;
		System.out.println(Thread.currentThread().getName() + "存钱" + m
				+ "元,现在余额是" + money + "元");
		// this.notifyAll();

	}

	// 取钱
	public synchronized void takeMoney(int m) {
		System.out.println(Thread.currentThread().getName() + "准备取钱" + m
				+ "元，现在余额是" + this.getMoney() + "元");
		while (money < m) {
			try {
				System.out.println(Thread.currentThread().getName() + "准备取钱"
						+ m + "元，现在余额是" + this.getMoney() + "元,余额不足，等着");
				this.wait();
				System.out.println(Thread.currentThread().getName()
						+ "被喊醒，准备取钱" + m + "元");
			} catch (InterruptedException e) {
				// TODO 自动生成的 catch 块
				e.printStackTrace();
			}
		}

		money -= m;
		System.out.println(Thread.currentThread().getName() + "取钱" + m
				+ "元成功，现在余额是" + this.getMoney() + "元");

	}

	private void setKai(String k) {
		this.kaihuriqi = k;
	}

	public void show() {
		System.out.println("账号" + no + ",开户于" + this.kaihuriqi + ",余额是"
				+ this.money + "元");
	}
}
